const { SuccessModel } = require("../model/responseModel");
const {
  getList,
  getDetail,
  addBlog,
  update,
  deleteBlog
} = require('../getdata/blog');

const handleBlogRouter = (req, res) => {
  const method = req.method;
  const reqData = req.body;

  if (method === 'GET' && req.path === '/api/blog/list') {
    const author = req.query.author;
    const keyword = req.query.keyword;
    return getList(author, keyword).then(responseData => {
      return new SuccessModel(responseData);
    });
  }
  if (method === 'GET' && req.path === '/api/blog/detail') {
    const id = req.query.id;
    return getDetail(id).then(responseData => {
      return new SuccessModel(responseData);
    });
  }
  if (method === 'POST' && req.path === '/api/blog/add') {
    return addBlog(reqData).then(responseData => {
      return new SuccessModel({
        id: responseData.insertId
      })
    })
  }
  if (method === 'POST' && req.path === '/api/blog/update') {
    return update(reqData).then(responseData => {
      return new SuccessModel({
        id: responseData.insertId
      })
    })
  }
  if (method === 'POST' && req.path === '/api/blog/delete') {
    return deleteBlog(reqData).then(responseData => {
      console.log(responseData)
      return new SuccessModel({
        id: responseData.insertId
      })
    })
  }
  if (method === 'POST' && req.path === '/monitor/sys/login') {
    console.log(reqData)
    return new SuccessModel({
      "success": true,
      "message": "",
      "code": 0,
      "data": {
        "userInfo": {
          "roleCode": "Administrator",
          "roleName": "超级管理员",
          "fullname": "超级管理员",
          "avatar": "https://oss.mrd5.5mrj.com/dev/other/1d082c35-64bd-4e9f-ad2b-3a205270b223.",
          "userId": "1711993273230426112",
          "username": "admin"
        },
        "websocketUrl": "ws://192.168.2.190:20144",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjMzNDE0MjgsInVzZXJuYW1lIjoiYWRtaW4ifQ.4sc07BiAKQVx1RnKA5NisNZtWiuEvZMyhse30gOVILs"
      },
      "timestamp": "1722736628628"
    })
  }
  if (method === 'POST' && req.path === '/gtxpnp/network/setting') {
    return new SuccessModel({
      "Command": "basic_gpnplogin",
      "StateCode": 200,
      "State": "OK",
      "TokenID": "59ea6b3d-1787-4f9f8-873d-e67642790904",
      "CamParam": { //(Object类型)相机参数
        "CameraExpose": 2.0, //(float类型)相机曝光参数 单位ms
        "CameraGain": 5, //(int类型)相机增益 单位db
        "CameraGray": 20, //(int类型)相机灰度阈值 单位像素 范围(1-255)
        "CameraLowGray": 255, //(int类型)相机灰度低阈值 单位像素 范围(1-255)
        "CameraTimeOut": 1000, //(int类型)相机重连时间 单位ms
        "CameraColStart": 0, //(int类型)图像ROI列开始
        "CameraColWidth": 2048, //(int类型)图像ROI列宽度
        "CameraRowStart": 0, //(int类型)图像ROI行开始
        "CameraRowHeight": 176, //(int类型)图像ROI行高度
        "InternalFreq": 500, //(int类型)内触发频率
        "CameraFresy": 1.1, //(float类型)每帧间隔距离
        "LaserMode": 1, //(int类型)激光发射模式 0-不常亮 1-常亮
        "RoiColStart": 0, //(int类型)ROI列起始
        "RoiColMax": 2048, //(int类型)ROI列最大
        "RoiRowStart": 0, //(int类型)ROI行起始
        "RoiRowMax": 176, //(int类型)ROI行最大
        "CameraLineNumber": 12,
      }
    })
  }
  if (method === 'POST' && req.path === '/api/sys/login') {
    return new SuccessModel({
      "success": true,
      "message": "",
      "code": 0,
      "data": {
        "userInfo": {
          "roleCode": "Administrator",
          "roleName": "超级管理员",
          "tenantId": "0",
          "fullname": "超级管理员",
          "avatar": "https://oss.mrd5.5mrj.com/dev/other/4e2fc81856fc44b59adfd2f1c5c4777d.jpg",
          "userId": "1711993273230426112",
          "username": "admin"
        },
        "expire": "1209600",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDA1MzgxNjUsInVzZXJuYW1lIjoiYWRtaW4ifQ.hhAna0Dkl1l_npkC4aUSW9BK9sapEnOGiLGo5Ts4NiM"
      },
      "timestamp": "1739933365039"
    })
  }
}

module.exports = handleBlogRouter;